home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp95 / freyja13.exe / lha / HELP.C < prev    next >
C/C++ Source or Header  |  1992-03-22  |  8KB  |  358 lines

  1. /* HELP.C -- Help Command
  2.  
  3.     Written March 1991 by Craig A. Finseth
  4.     Copyright 1991 by Craig A. Finseth
  5. */
  6.  
  7. #include "freyja.h"
  8.  
  9. #define ZCA    '\001'
  10. #define ZCC    '\003'
  11. #define ZCF    '\006'
  12. #define ZCU    '\025'
  13. #define ZCW    '\027'
  14.  
  15. void Help_Apropos();        /* void */
  16. void Help_Ascii();        /* void */
  17. void Help_Bindings();        /* void */
  18. void Help_Describe();        /* void */
  19. void Help_File();
  20.  
  21. /* ------------------------------------------------------------ */
  22.  
  23. /* Help. */
  24.  
  25. void
  26. HHelp()
  27.     {
  28.     int chr;
  29.     FLAG isdone = FALSE;
  30.  
  31.     uarg = 0;
  32.     if (!FMakeSys(SYS_HELP, TRUE)) return;
  33.  
  34.     while (!isdone) {
  35.         DIncrDisplay();
  36.         KDelayPrompt("Help:");
  37.  
  38.         chr = KGetChar();
  39.         isdone = TRUE;
  40.         switch (xtoupper(chr)) {
  41.  
  42.         case KEYQUIT:
  43.         case KEYABORT:
  44.         case BEL:
  45.         case ESC:
  46.             DModeLine();
  47.             break;
  48.  
  49.         case ZCA:        /* ascii chart */
  50.             Help_Ascii();
  51.             break;
  52.  
  53.         case ZCC:        /* copying info */
  54.             Help_File(COPYING_FILE);
  55.             break;
  56.  
  57.         case ZCF:        /* FSF info */
  58.             Help_File(FSF_FILE);
  59.             break;
  60.  
  61.         case FF:        /* league info */
  62.             Help_File(LEAGUE_FILE);
  63.             break;
  64.  
  65. #if !defined(NOCALC)
  66.         case ZCU:        /* calculator info */
  67.             Help_File(CALCULATOR_FILE);
  68.             break;
  69. #endif
  70.  
  71.         case ZCW:        /* warranty info */
  72.             Help_File(WARRANTY_FILE);
  73.             break;
  74.  
  75.         case 'A':        /* apropos */
  76.             Help_Apropos();
  77.             break;
  78.  
  79.         case 'B':        /* bindings */
  80.             Help_Bindings();
  81.             break;
  82.  
  83.         case 'C':        /* command list */
  84.             Help_File(CMDLIST_FILE);
  85.             break;
  86.  
  87.         case 'F':        /* describe key */
  88.             Help_Describe();
  89.             break;
  90.  
  91.         case 'I':        /* info */
  92.             Help_File(INFO_FILE);
  93.             break;
  94.  
  95.         case 'T':        /* tutorial */
  96.             Help_File(TUTORIAL_FILE);
  97.             break;
  98.  
  99.         case 'X':        /* xref */
  100.             Help_File(XREF_FILE);
  101.             break;
  102.  
  103.         case '?':        /* quick help */
  104.             DEcho(
  105. #if !defined(NOCALC)
  106. "^A ^C ^F ^L ^U ^W A B C F I T X ?       H for more help");
  107. #else
  108. "^A ^C ^F ^L ^W A B C F I T X ?       H for more help");
  109. #endif
  110.             isdone = FALSE;
  111.             break;
  112.  
  113. #if defined(MSDOS)
  114.         case KEYHELP:
  115. #endif
  116.         case BS:        /* help on help */
  117.         case 'H':
  118.         case DEL:
  119.             BInsStr(
  120. #if !defined(NOCALC)
  121. "^X H ^A        Build an ASCII chart.\n\
  122. ^X H ^C        Display copying information.\n\
  123. ^X H ^F        Display Free Software Foundation information.\n\
  124. ^X H ^L        Display League for Programming Freedom information.\n\
  125. ^X H ^U        Display calculator information.\n\
  126. ^X H ^W        Display warranty information.\n\
  127. ^X H A        Apropos; ask for a string and display relevant commands.\n\
  128. ^X H B        Describe key bindings; does not list self-insert or\n\
  129.         bad cmds (constructed from the command tables).\n\
  130. ^X H C        Display the command list document.\n\
  131. ^X H F        Ask for a key and describes what the key does.\n\
  132. ^X H I        Info: Brings up the FREYJA.DOC file.\n\
  133. ^X H T        Tutuorial: Brings up the FTUTORIA.DOC file.\n\
  134. ^X H X        Display command cross reference information.\n\
  135. ^X H ^H        Help on help.\n\
  136. ^X H ?        Short help on help.\n\
  137. ^X H H        Help on help.\n\
  138. ^X H ^?        Help on help.\n");
  139. #else
  140. "^X H ^A        Build an ASCII chart.\n\
  141. ^X H ^C        Display copying information.\n\
  142. ^X H ^F        Display Free Software Foundation information.\n\
  143. ^X H ^L        Display League for Programming Freedom information.\n\
  144. ^X H ^U        (This version compiled without the calculator.\n\
  145. ^X H ^W        Display warranty information.\n\
  146. ^X H A        Apropos; ask for a string and display relevant commands.\n\
  147. ^X H B        Describe key bindings; does not list self-insert or\n\
  148.         bad cmds (constructed from the command tables).\n\
  149. ^X H C        Display the command list document.\n\
  150. ^X H F        Ask for a key and describes what the key does.\n\
  151. ^X H I        Info: Brings up the FREYJA.DOC file.\n\
  152. ^X H T        Tutuorial: Brings up the FTUTORIA.DOC file.\n\
  153. ^X H X        Display command cross reference information.\n\
  154. ^X H ^H        Help on help.\n\
  155. ^X H ?        Short help on help.\n\
  156. ^X H H        Help on help.\n\
  157. ^X H ^?        Help on help.\n");
  158. #endif
  159.             isdone = FALSE;
  160.             break;
  161.  
  162.         default:
  163.             TBell();
  164.             isdone = FALSE;
  165.             break;
  166.             }
  167.         BMoveToStart();
  168.         }
  169.     DWindSwap();
  170.     DModeLine();
  171.     }
  172.  
  173.  
  174. /* ------------------------------------------------------------ */
  175.  
  176. /* Handle apropos. */
  177.  
  178. void
  179. Help_Apropos()
  180.     {
  181.     char buf[LINEBUFFSIZE];
  182.     char what[LINEBUFFSIZE];
  183.     int wlen;
  184.     int key;
  185.     int table;
  186.     char *hptr;
  187.     char *cptr;
  188.  
  189.     *what = NUL;
  190.     if (KGetStr("Apropos", what, sizeof(what)) != 'Y') return;
  191.     wlen = strlen(what);
  192.  
  193.     for (table = 0; table < 3; table++) {
  194.         for (key = 0; key < 128; key++) {
  195.             hptr = TabHelp(key, table);
  196.             if (*hptr == '@' && *hptr == '^') continue;
  197.  
  198.             for (cptr = hptr; *cptr != NUL;
  199.                   cptr = sindex(cptr, SP)) {
  200.                 if (*cptr == SP) cptr++;
  201.                 if (strnequ(what, cptr, wlen)) break;
  202.                 }
  203.             if (*cptr == NUL) continue;
  204.  
  205.             xsprintf(buf, "%s    %s\n",     TabDescr(key, table),
  206.                 hptr);
  207.             BInsStr(buf);
  208.             }
  209.         }
  210.     for (key = 0; key < TabNumFunc(); key++) {
  211.         hptr = TabHelp(key, 3);
  212.         if (*hptr == '@' && *hptr == '^') continue;
  213.  
  214.         for (cptr = hptr; *cptr != NUL; cptr = sindex(cptr, SP)) {
  215.             if (*cptr == SP) cptr++;
  216.             if (strnequ(what, cptr, wlen)) break;
  217.             }
  218.         if (*cptr == NUL) continue;
  219.  
  220.         xsprintf(buf, "%s    %s\n",     TabDescr(key, 3), hptr);
  221.         BInsStr(buf);
  222.         }
  223. #if !defined(NOCALC)
  224.     for (key = 0; key < UNumOps(); key++) {
  225.         hptr = UHelp(key);
  226.         for (cptr = hptr; *cptr != NUL;
  227.               cptr = sindex(cptr, SP)) {
  228.             if (*cptr == SP) cptr++;
  229.             if (strnequ(what, cptr, wlen)) break;
  230.             }
  231.         if (*cptr == NUL) continue;
  232.  
  233.         xsprintf(buf, "%s    %s\n",     UDescr(key), hptr);
  234.         BInsStr(buf);
  235.         }
  236. #endif
  237.     }
  238.  
  239.  
  240. /* ------------------------------------------------------------ */
  241.  
  242. /* Build an ASCII chart. */
  243.  
  244. void
  245. Help_Ascii()
  246.     {
  247.     char buf[LINEBUFFSIZE];
  248.     int cnt;
  249.  
  250.     xsprintf(buf, "%d    %o    %x    %s    %c\n",
  251.         0, 0, 0, TPrintChar(0, NULL), 0);
  252.     BInsStr(buf);
  253.     BInsChar(NUL);
  254.     BInsChar(NL);
  255.     for (cnt = 1; cnt < 256; cnt++) {
  256.         xsprintf(buf, "%d    %o    %x    %s    %c\n",
  257.             cnt, cnt, cnt, TPrintChar(cnt, NULL), cnt);
  258.         BInsStr(buf);
  259.         }
  260.     }
  261.  
  262.  
  263. /* ------------------------------------------------------------ */
  264.  
  265. /* Build a key bindings table. */
  266.  
  267. void
  268. Help_Bindings()
  269.     {
  270.     char buf[LINEBUFFSIZE];
  271.     int key;
  272.     int table;
  273.     char *cptr;
  274.  
  275.     for (table = 0; table < 3; table++) {
  276.         for (key = 0; key < 128; key++) {
  277.             cptr = TabHelp(key, table);
  278.             if (*cptr != '@' && *cptr != '^') {
  279.                 xsprintf(buf, "%s    %s\n",
  280.                     TabDescr(key, table),
  281.                     cptr);
  282.                 BInsStr(buf);
  283.                 }
  284.             }
  285.         }
  286.     for (key = 0; key < TabNumFunc(); key++) {
  287.         cptr = TabHelp(key, 3);
  288.         if (*cptr != '@' && *cptr != '^') {
  289.             xsprintf(buf, "%s    %s\n", TabDescr(key, 3), cptr);
  290.             BInsStr(buf);
  291.             }
  292.         }
  293. #if !defined(NOCALC)
  294.     for (key = 0; key < UNumOps(); key++) {
  295.         xsprintf(buf, "%s    %s\n", UDescr(key), UHelp(key));
  296.         BInsStr(buf);
  297.         }
  298. #endif
  299.     }
  300.  
  301.  
  302. /* ------------------------------------------------------------ */
  303.  
  304. /* Ask for a key and describe what it does. */
  305.  
  306. void
  307. Help_Describe()
  308.     {
  309.     char buf[LINEBUFFSIZE];
  310.     char *cptr;
  311.     int key;
  312.     int table;
  313.  
  314.     DEcho("Key: ");
  315.     key = KGetChar();
  316.  
  317.     table = TabTable(key, 0);
  318.     if (table == 1 || table == 2) {
  319.         xsprintf(buf, "%s ", TabDescr(key, 0));
  320.         DEcho(buf);
  321.         key = KGetChar();
  322.         }
  323.  
  324.     cptr = TabHelp(key, table);
  325.     if (*cptr == '@') cptr = "not a command";
  326.     else if (*cptr == '^') cptr = "self-insert";
  327.  
  328.     xsprintf(buf, "%s   %s", TabDescr(key, table), cptr);
  329.     DView(buf);
  330.     }
  331.  
  332.  
  333. /* ------------------------------------------------------------ */
  334.  
  335. /* Load the specified file. */
  336.  
  337. void
  338. Help_File(fname)
  339.     char *fname;
  340.     {
  341.     char realname[FNAMEMAX];
  342.     char buf[FNAMEMAX];
  343.     int fd;
  344.  
  345.     if ((fd = FPathOpen(fname, realname)) < 0) {
  346.         xsprintf(buf, "Can't find file '%s'", fname);
  347.         DError(buf);
  348.         return;
  349.         }
  350.     close(fd);
  351.  
  352.     xstrncpy(cbuf->fname, realname);
  353.     BFileRead();
  354.     }
  355.  
  356.  
  357. /* end of HELP.C -- Help Command */
  358.